<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title></title>
    <!-- Bootstrap Styles-->
    <link href="__BACK__/css/bootstrap.css" rel="stylesheet"/>
    <!-- FontAwesome Styles-->
    <link href="__BACK__/css/font-awesome.css" rel="stylesheet"/>
    <!-- Custom Styles-->
    <link href="__BACK__/css/custom-styles.css" rel="stylesheet"/>
    <!-- Google Fonts-->
    <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'/>
    <script src="__BACK__/js/jquery-1.11.1.min.js"></script>
    <script>
        //图片上传预览    IE是用了滤镜。
        function previewImage(file)
        {
            var MAXWIDTH  = 150;
            var MAXHEIGHT = 150;
            var div = document.getElementById('preview');
            if (file.files && file.files[0])
            {
                div.innerHTML ='<img id=imghead onclick=$("#previewImg").click()>';
                var img = document.getElementById('imghead');
                img.onload = function(){
                    var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
                    img.width  =  rect.width;
                    img.height =  rect.height;
//                 img.style.marginLeft = rect.left+'px';
                    img.style.marginTop = rect.top+'px';
                }
                var reader = new FileReader();
                reader.onload = function(evt){
                    img.src = evt.target.result;
                    $('#thumb').val(evt.target.result);
                    $('#del').css("display","block")
                }
                reader.readAsDataURL(file.files[0]);
                // $('#preview').append("<button>取消</button>");
            }
            else //兼容IE
            {
                var sFilter='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
                file.select();
                var src = document.selection.createRange().text;
                div.innerHTML = '<img id=imghead>';
                var img = document.getElementById('imghead');
                img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
                var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
                status =('rect:'+rect.top+','+rect.left+','+rect.width+','+rect.height);
                div.innerHTML = "<div id=divhead style='width:"+rect.width+"px;height:"+rect.height+"px;margin-top:"+rect.top+"px;"+sFilter+src+"\"'></div>";
            }
        }
        function clacImgZoomParam( maxWidth, maxHeight, width, height ){
            var param = {top:0, left:0, width:width, height:height};
            if( width>maxWidth || height>maxHeight ){
                rateWidth = width / maxWidth;
                rateHeight = height / maxHeight;

                if( rateWidth > rateHeight ){
                    param.width =  maxWidth;
                    param.height = Math.round(height / rateWidth);
                }else{
                    param.width = Math.round(width / rateHeight);
                    param.height = maxHeight;
                }
            }
            param.left = Math.round((maxWidth - param.width) / 2);
            param.top = Math.round((maxHeight - param.height) / 2);
            return param;
        }

        $(function () {

            $('#del').click(function () {
                $('#imghead').attr('src','__BACK__/img/upload-bj1.png');
                $('#thumb').val(null);
                $(this).hide();
            })
        });




    </script>
</head>
<body>
<div id="wrapper">
    {include file="public/top"}
    <!--/. NAV TOP  -->
    {include file="public/left"}
    <!--/. NAV TOP  -->
    <div id="page-wrapper">
        <div id="page-inner">
            <div class="row">
                <div class="col-md-12">
                    <h1 class="page-header">
                        帮助设置
                    </h1>
                </div>
            </div>
            <!-- /. ROW  -->
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-5">
                                    <form action="" method="post" class="form-horizontal" role="form">
                                        <div class="form-group">
                                            <h4 for="1" class="col-sm-5">联系客服</h4>
                                        </div>
                                        <div class="form-group">
                                            <label for="2" class="col-sm-2 control-label">标题:</label>
                                            <div class="col-sm-10">
                                                <input type="text" name="title" id="title" class="form-control" value="{$service['title']}"
                                                       title="">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label for="4" class="col-sm-2 control-label">文字内容:</label>
                                            <div class="col-sm-10">
                                                <textarea name="content" id="content" class="form-control" rows="6">
                                                    {$service['content']}
                                                </textarea>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label for="inputID" class="col-sm-2 control-label">其他:</label>
                                            <div class="col-sm-10">
                                                <input type="text" name="other" id="other" class="form-control" value="{$service['other']}"
                                                       title="">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label for="3" class="col-sm-2 control-label">图片上传:</label>
                                            <div class="col-sm-10">
                                                <div class="col-sm-9 big-photo">
                                                    <div id="preview">
                                                        <img id="imghead" border="0" src="{:isset($service['thumb'])?$service['thumb']:'__BACK__/img/upload-bj1.png'}" width="150" height="150" onclick="$('#previewImg').click();">
                                                    </div>
                                                    <div style="width: 150px; height: 20px; background:grey; text-align: center" id="del"><span style="color: white">删除</span></div>
                                                    <input type="file" onchange="previewImage(this)" style="display: none;" id="previewImg">
                                                    <!--<input id="uploaderInput" class="uploader__input" style="display: none;" type="file" accept="" multiple="">-->
                                                    <input type="hidden" name="thumb" id="thumb" value="{$service['thumb']}">
                                                </div>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <div class="col-sm-10 col-sm-offset-2">
                                                <button type="submit" class="btn btn-primary">保存</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <footer>
            </footer>
        </div>
        <!-- /. PAGE INNER  -->
    </div>
    <!-- /. PAGE WRAPPER  -->
</div>
<!-- /. WRAPPER  -->
    <!-- /. NAV SIDE  -->
    <!-- /. PAGE WRAPPER  -->
</div>

</body>
</html>
